package com.str.graphs;

import com.str.PQ.HeapPriorityQueue;
import com.str.PQ.PriorityQueue;

public class DijkstraTest {

  private static final int NUM = 5; // Number of vertices
  private static final boolean UNDIRECTED = true;
  
  // Create a graph from array
  public static Graph createGraph(int[][] examp) {
    Graph g = new MatrixGraph(NUM);
   // Graph g = new ListGraph(NUM);

    for (int i=0; i<examp.length; i++) {
      int v1 = examp[i][0];
      int v2 = examp[i][1];
      int dist = 1;  // No weight given -- set at 1       
      if (examp[i].length > 2)
        dist = examp[i][2];
      g.setEdge(v1, v2, dist);
      if (UNDIRECTED) // Also put in edge in other direction
        g.setEdge(v2, v1, dist);
    }
    return g;
  }

  public static void print(Graph g) {
    System.out.println("Number of vertices is " + g.n());
    System.out.println("Number of edges is " + g.e());

    System.out.println("Matrix is:");
    for (int i=0; i<g.n(); i++) {
      for (int j=0; j<g.n(); j++)
        System.out.print(g.weight(i, j) + "  ");
      System.out.println();
    }
    System.out.println();
  }

  // Generic main function for graph tests --
  //   both adjacency list and adjacency graph
  public static void main(String args[]) {
  	
    int[][] examp = {{0, 1, 10},
                     {0, 2,  3},    
                     {0, 3, 20},
                     {1, 3,  5},
                     {2, 1,  2},
                     {2, 4, 15},
                     {3, 4, 11}};	
    Graph g = createGraph(examp);
    print(g);
    Dijkstra.dijkstra(g, 0);
    System.out.println();

    PriorityQueue h = new HeapPriorityQueue();   // Create the heap 
    Dijkstra2.dijkstra(g, 0, h);
  }
}
